package com.example.lenovo.weiyi;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.com.ruanmeng.demon.ErWeiMaM;
import com.com.ruanmeng.demon.PerMessM;
import com.com.ruanmeng.utils.CommonUtil;
import com.com.ruanmeng.utils.ImgDataUtil;
import com.com.ruanmeng.utils.PreferencesUtils;
import com.yolanda.nohttp.NoHttp;
import com.yolanda.nohttp.rest.Request;

import org.json.JSONException;
import org.json.JSONObject;

import butterknife.BindView;
import butterknife.ButterKnife;
import nohttp.CallServer;
import nohttp.CustomHttpListener;
import share.Const;
import share.HttpIP;

/**
 * Created by Administrator on 2017/5/5.
 */

public class MyErWeiMaActivity extends BaseActivity {
    @BindView(R.id.iv_my_erweima)
    ImageView ivMyErweima;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_erweima);
        ButterKnife.bind(this);
        if (!TextUtils.isEmpty(getIntent().getStringExtra("per"))) {
            ChangLayTitle("我的二维码");
        } else {
            ChangLayTitle("二维码");
        }
        getData();
    }

    private void getData() {
        Request<String> mRequest = NoHttp.createStringRequest(HttpIP.ErWeiMa, Const.POST);
        mRequest.addHeader("token", PreferencesUtils.getString(MyErWeiMaActivity.this, "uid"));
        CallServer.getRequestInstance().add(MyErWeiMaActivity.this, 0, mRequest,
                new CustomHttpListener(MyErWeiMaActivity.this, true, ErWeiMaM.class) {
                    @Override
                    public void doWork(Object data, boolean isOne) {
                        ErWeiMaM model = ((ErWeiMaM) data);
                        ivMyErweima.setImageBitmap(CommonUtil.stringtoBitmap(model.getObject()));
                    }

                    @Override
                    public void onFinally(JSONObject obj) throws JSONException {
                        super.onFinally(obj);
                    }
                }, true, true);
    }
}
